public class Problem21 {
	public static void main(String[] args) {
		int sum1 = 0;
		int sum2 = 0;

		for (int i = 2; i < 10000; i++) {
			int j = amicable(i);
			if (amicable(j) == i && i != j) {
				if (j < 10000)
					sum2 += i + j;
				else
					sum1 += i;
			}
		}

		System.out.println("" + ((sum2>>1) + sum1));
	}

	private static int amicable(int n) {
		assert (n >= 2);
		int sum = 0;
		for (int i = 1; i <= Math.sqrt(n); ++i) {
			if (n % i == 0) {
				sum += i;
				sum += n/i;
			}
		}

		if (((int)Math.sqrt(n))*((int)Math.sqrt(n)) == n)
			sum -= Math.sqrt(n);

		sum -= n;
		return sum;
	}
}
